package Test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ggame extends JFrame {

	private JPanel contentPane;
	private JScrollPane scrollPane;
	private JTextArea result;
	private JButton btnNewButton;
	private JLabel lblNewLabel;
	private JTextField str;
	private JButton btnNewButton_1;

	
	int a = (int) (Math.random() * 1000) + 1;
	int count = 0;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ggame frame = new ggame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ggame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getScrollPane());
		contentPane.add(getBtnNewButton());
		contentPane.add(getLblNewLabel());
		contentPane.add(getStr());
		contentPane.add(getBtnNewButton_1());
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 10, 410, 85);
			scrollPane.setViewportView(getResult());
		}
		return scrollPane;
	}

	private JTextArea getResult() {
		if (result == null) {
			result = new JTextArea();
		}
		return result;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("입력");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {

					//System.out.println(a); // 값을 보여준다
					String e = str.getText();
					int i = Integer.parseInt(e);
					result.append("" + i);
					
					
						if (a == i) { // a 가 난수, i = getText입력값
							result.append("\n이기셨네요 대단합니다 존경 스럽습니다 우러러볼게요 존경합니다");
							result.append("\n");
							count++;
							result.append("\n실행한 횟수:"+count);
							
						} else if (a > i) {
							result.append("\n업업업 사람이 배짱이 있어야지");
							result.append("\n");
							count++;
							
							
						} else if (a < i) {
							result.append("\n간땡이가 배밖으로 튀어 나오셨네요 작작 배팅하세요");
							result.append("\n");
							count++;
							
							
						}
					
				}
			});
			btnNewButton.setBounds(12, 180, 97, 23);
		}
		return btnNewButton;
	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("입력창");
			lblNewLabel.setBounds(12, 124, 57, 15);
		}
		return lblNewLabel;
	}

	private JTextField getStr() {
		if (str == null) {
			str = new JTextField();
			str.setBounds(84, 121, 116, 21);
			str.setColumns(10);
		}
		return str;
	}

	private JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton("리셋");
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					result.setText("");
					count = 0;
				}
			});
			btnNewButton_1.setBounds(121, 180, 97, 23);
		}
		return btnNewButton_1;
	}
}
